home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / sana2_cslip.lha / slip_device.h < prev    next >
C/C++ Source or Header  |  1993-06-25  |  6KB  |  208 lines

  1. /*
  2. ** $Source: hog:Other/networking/sana2/src/slip/RCS/slip_device.h,v $
  3. ** $State: Exp $
  4. ** $Revision: 37.2 $
  5. ** $Date: 92/08/25 16:43:51 $
  6. ** $Author: kcd $
  7. **
  8. ** SANA-II Example device driver C include file
  9. **
  10. ** (C) Copyright 1992 Commodore-Amiga, Inc.
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/devices.h>
  15. #include <exec/ports.h>
  16. #include <exec/semaphores.h>
  17. #include <exec/memory.h>
  18. #include <dos.h>
  19. #include "devices/sana2.h"
  20. #include <devices/serial.h>
  21.  
  22. /*
  23. ** Choose here if you want slip or compressed slip
  24. */
  25. #ifndef CSLIP
  26. #define CSLIP    1
  27. #endif
  28.  
  29. #if CSLIP
  30. #include "cslip.h"
  31. #else
  32. #define MAX_HDR     0
  33. #endif
  34.  
  35. /*
  36. ** Stacksize and Priority of the Unit Process
  37. */
  38. #define SLIP_STACKSIZE 4000
  39. #define SLIP_PRI 5
  40.  
  41. /*
  42. ** Maximum Transmission Unit
  43. */
  44. #define SLIP_MTU 1006
  45. #define BUF_SLOP 4
  46.  
  47. /*
  48. ** Max # of Units allowed
  49. */
  50. #define SD_MAXUNITS 8
  51.  
  52. /*
  53. ** Message passed to the Unit Process at
  54. ** startup time.
  55. */
  56. struct StartupMessage
  57. {
  58.     struct Message    Msg;
  59.     struct Unit    *Unit;
  60.     struct Device    *Device;
  61. };
  62.  
  63. /*
  64. ** Device Data Structure
  65. */
  66. struct SLIPDevice
  67. {
  68.     struct Library     sd_Device;
  69.     UBYTE         sd_Flags;
  70.     UBYTE         sd_Pad1;
  71.     struct Library    *sd_SysBase;
  72.     struct Library    *sd_DOSBase;
  73.     ULONG         sd_DosTag[10];
  74.     BPTR         sd_SegList;
  75.     struct Unit     *sd_Units[SD_MAXUNITS];
  76.     struct SignalSemaphore sd_Lock;
  77.     struct StartupMessage sd_Startup;
  78. };
  79.  
  80. /*
  81. ** Typedef's for the SANA-II callback functions.
  82. ** Rhialto: It would be nice to specify the registers explicitly,
  83. ** instead of hoping the compiler options include ARGS=REGS, and that
  84. ** the compiler selected registers would match the requirements.
  85. */
  86. #ifdef __SASC
  87. #define ASM          __asm
  88. #define REG(x)        register __ ## x
  89. #else
  90. #error Please define ASM and REG for your compiler
  91. #endif
  92.  
  93. typedef BOOL (*ASM SANA2_CFB)(REG(a0) APTR to, REG(a1) APTR from, REG(d0) LONG length);
  94. typedef BOOL (*ASM SANA2_CTB)(REG(a0) APTR to, REG(a1) APTR from, REG(d0) LONG length);
  95.  
  96. struct BufferManagement
  97. {
  98.     struct MinNode    bm_Node;
  99.     SANA2_CFB        bm_CopyFromBuffer;
  100.     SANA2_CTB        bm_CopyToBuffer;
  101. };
  102.  
  103. struct SuperS2PTStats
  104. {
  105.     struct MinNode        ss_Node;
  106.     ULONG            ss_PType;
  107.     struct Sana2PacketTypeStats ss_Stats;
  108. };
  109.  
  110. /*
  111. ** Unit Data Structure
  112. */
  113. struct SLIPDevUnit
  114. {
  115.     struct Unit          sdu_Unit;        /* Standard Unit Structure */
  116.     UBYTE             sdu_UnitNum;        /* Unit number */
  117.     UBYTE             sdu_Reserved0;     /* Padding */
  118.     struct Device        *sdu_Device;        /* Pointer to our device node */
  119.     ULONG             sdu_StAddr;        /* Our current address */
  120.     ULONG             sdu_HwAddr;        /* Our "hardware" address (Rhialto)*/
  121.     ULONG             sdu_BaudRate;        /* Serial baud rate */
  122.     ULONG             sdu_SerUnitNum;    /* Serial driver unit number */
  123.     BOOL             sdu_NoMore;        /* ??? */
  124.     BOOL             sdu_Escape;        /* SLIP Decode state */
  125.     ULONG             sdu_State;        /* Various state information */
  126.     struct IOExtSer        *sdu_SerRx;        /* Serial IORequest for CMD_READ's */
  127.     struct IOExtSer        *sdu_SerTx;        /* Serial IORequest for CMD_WRITE's */
  128.     struct MsgPort        *sdu_RxPort;        /* Serial CMD_READ IORequest reply port */
  129.     struct MsgPort        *sdu_TxPort;        /* Serial CMD_WRITE IORequest reply port */
  130.     UBYTE            *sdu_RxBuff;        /* Buffer for holding decoded packets */
  131.     UBYTE            *sdu_RxBuffPtr;     /* Current place in decode buffer */
  132.     UBYTE            *sdu_TxBuff;        /* Temporary buffer for hold unencoded outgoing packets */
  133.     UBYTE            *sdu_RxSLIP;        /* Two buffers that hold packets encoded */
  134.     UBYTE            *sdu_TxSLIP;        /* in SLIP format. */
  135.     struct Process        *sdu_Proc;        /* NB: This points to the Task, not the MsgPort */
  136.     struct SignalSemaphore     sdu_ListLock;        /* A Semaphore for access to all of our queues. */
  137.     struct MinList         sdu_Rx;        /* Pending CMD_READ's */
  138.     struct MinList         sdu_RxOrph;        /* Pending CMD_READORPHAN's */
  139.     struct MinList         sdu_Tx;        /* Pending CMD_WRITE's */
  140.     struct MinList         sdu_Events;        /* Pending S2_ONEVENT's */
  141.     struct SuperS2PTStats    *sdu_IPTrack;        /* For tracking IP packets */
  142.     struct MinList         sdu_Track;        /* List of packet types being tracked */
  143.     struct MinList         sdu_BuffMgmt;        /* List of Callback routines */
  144.     struct Sana2DeviceStats     sdu_Stats;        /* Global device statistics */
  145.     UBYTE             sdu_SerDevName[32];    /* Name of the serial driver to use */
  146. #if CSLIP
  147.     struct slcompress         sdu_slcompress;
  148. #endif
  149. };
  150.  
  151. /*
  152. ** State bits for sdu_State
  153. */
  154.  
  155. #define SLIPUB_CONFIG 0
  156. #define SLIPUB_ONLINE 1
  157. #define SLIPUB_SETCONFIG 2
  158. #define SLIPUB_CD 3
  159. #define SLIPUB_EXCLUSIVE 4
  160. #define SLIPUB_7WIRE 5
  161.  
  162. #define SLIPUF_CONFIG        (1<<SLIPUB_CONFIG)
  163. #define SLIPUF_ONLINE        (1<<SLIPUB_ONLINE)
  164. #define SLIPUF_SETCONFIG    (1<<SLIPUB_SETCONFIG)
  165. #define SLIPUF_CD        (1<<SLIPUB_CD)
  166. #define SLIPUF_EXCLUSIVE    (1<<SLIPUB_EXCLUSIVE)
  167. #define SLIPUF_7WIRE        (1<<SLIPUB_7WIRE)
  168.  
  169. /*
  170. ** Device Name
  171. */
  172.  
  173. #if CSLIP
  174. #define SLIPDEVNAME "cslip.device"
  175. #else
  176. #define SLIPDEVNAME "slip.device"
  177. #endif
  178. extern char SLIPName[];
  179.  
  180. /*
  181. ** Packet Encoding Bytes
  182. */
  183.  
  184. #define SLIP_END     192
  185. #define SLIP_ESC     219
  186. #define SLIP_ESC_END 220
  187. #define SLIP_ESC_ESC 221
  188.  
  189. /*
  190. ** Compiler Magic
  191. **
  192. ** (Rhialto) This is terrible!!! That people write code like this!
  193. ** How can you be sure the compiler won't use A6 for a register variable
  194. ** somewhere and make it unusable in the functions that it calls?
  195. ** (in fact, SAS/C 6.2 does something that, in ReadConfig..., when it
  196. ** first calls an Exec function and then a DOS function)
  197. */
  198.  
  199. #ifdef notdef
  200. #define SLIPBase ((struct SLIPDevice *)__builtin_getreg(14))    /* Avoid the pre-processor problem */
  201. #else
  202. #define SLIPBase    ExtDeviceBase
  203. #endif
  204.  
  205. #define SysBase     (SLIPBase->sd_SysBase)
  206. #define DOSBase     (SLIPBase->sd_DOSBase)
  207.  
  208.